from django.contrib import admin
from .models import Product, Image

# 产品管理界面
class ProductAdmin(admin.ModelAdmin):
    list_display = ('productname', 'subid', 'price', 'is_active', 'created_at', 'total_use', 'maxtimes')  # 显示的字段
    list_filter = ('is_active', 'subid')  # 可过滤字段
    search_fields = ('productname', 'description')  # 可搜索字段
    ordering = ('-created_at',)  # 默认按创建时间倒序排序
    date_hierarchy = 'created_at'  # 可以按时间层级过滤
    fields = ('productname', 'subid', 'description', 'price', 'total_use', 'is_active', 'created_at', 'covar_id', 'en_description', 'member_price', 'maxtimes')  # 需要显示的字段
    readonly_fields = ('created_at',)  # 只读字段

# 图片管理界面
class ImageAdmin(admin.ModelAdmin):
    list_display = ('name', 'url', 'type', 'created_at', 'format')  # 显示的字段
    list_filter = ('type',)  # 可过滤字段
    search_fields = ('name', 'description')  # 可搜索字段
    ordering = ('-created_at',)  # 默认按创建时间倒序排序
    fields = ('name', 'url', 'type', 'created_at', 'description', 'format')  # 需要显示的字段
    readonly_fields = ('created_at',)  # 只读字段

# 注册模型
admin.site.register(Product, ProductAdmin)
admin.site.register(Image, ImageAdmin)

# Register your models here.
